#import "RNConstants.h"

NSString *const RNRowKey = @"RNRowKey";
NSString *const RNTitleKey = @"title";
NSString *const RNCountKey = @"count";
NSString *const RNCompleteKey = @"complete";
NSString *const RNItemsKey = @"items";
NSString *const RNDisplayIndexKey = @"displayIndex";
NSString *const RNCountDictionaryKey = @"countDictionary";
NSString *const RNCompletionDictionaryKey = @"completionDictionary";
NSString *const RNTagsDictionaryKey = @"tagsDictionary";
NSString *const RNSearchMenuSeparatorItem = @"RNSearchMenuSeparatorItem";
NSString *const RNDisplayListByAisleKey = @"RNDisplayListByAisleKey";
NSString *const RNAllStoresTitle = @"All Stores";
NSString *const RNStoreFilterKey = @"StoreFilter";
NSString *const RNHideToolbarKey = @"RNHideToolbarKey";
NSString *const RNLogCompletedItemsIntervalKey = @"clearCompletedItemsInterval";
NSString *const RNLogCompletedItemsDateKey = @"RNLogCompletedItemsDateKey";
NSString *const RNClearHistoryIntervalComponentKey = @"clearHistoryIntervalComponent";
NSString *const RNClearHistoryIntervalAmountKey = @"clearHistoryIntervalAmount";

#pragma mark -
#pragma mark Entity name constants

NSString *const RNEntityNameAisle = @"RNAisle";
NSString *const RNEntityNameItem = @"RNItem";
NSString *const RNEntityNameList = @"RNList";
NSString *const RNEntityNameStore = @"RNStore";
NSString *const RNEntityNameListItem = @"RNListItem";
NSString *const RNEntityNameCategory = @"RNCategory";
NSString *const RNEntityNameHistoryItem = @"RNHistoryItem";
NSString *const RNClassNameCatalog = @"RNCatalog";
NSString *const RNClassNameFavorites = @"RNFavorites";
NSString *const RNClassNameHistory = @"RNHistory";

#pragma mark -
#pragma mark UTIs

NSString *const RNItemUTI = @"com.flytocode.raisins.item";
NSString *const RNListItemUTI = @"com.flytocode.raisins.listItem";
NSString *const RNUTIKey = @"UTI";
NSString* const RNDragDropUTI = @"com.flytocode.raisins";

#pragma mark -
#pragma mark Detail view cell keys
NSString *const RNDictionaryRepresentationKey = @"dictionaryRepresentation";
NSString* const RNDragDropObjectURIKey = @"RNDragDropObjectURIKey";
NSString* const RNPrintListContainerCellKey = @"RNPrintListContainerCellKey";
NSString* const RNPrintListItemCellKey = @"RNPrintListItemCellKey";
NSString* const RNEmptyCellKey = @"RNEmptyCell";
NSString* const RNDetailHeaderCellKey = @"RNDetailHeaderCell";
NSString* const RNSearchSubheaderCellKey = @"RNSearchSubheaderCell";
NSString* const RNListContainerCellKey = @"RNListCategoryCellKey";
NSString *const RNContainerCellKey = @"RNContainerCell";
NSString* const RNHistoryItemCellKey = @"RNHistoryItemCell";
NSString* const RNApplicationSearchTypeKey = @"RNApplicationSearchTypeKey";
NSString* const RNPrintContainerCellKey = @"RNPrintContainerCellKey";

#pragma mark -
#pragma mark Notifications

NSString* const RNEditItemViewDidHideNotification = @"RNEditItemViewDidHideNotification";
NSString* const RNListItemCompletionChangedNotification = @"RNListItemCompletionChangedNotification";

#pragma mark -
#pragma mark Layout constants

CGFloat const RNAddListItemCellHeight = 31.0f;
CGFloat const RNGenericCellEndPadding = 16.0f;
CGFloat const RNGenericCellElementPadding = 10.0f;
CGFloat const RNDetailViewBorderPadding = 6.0f;
CGFloat const RNDetailViewCellCornerRadius = 5.0f;
CGFloat const RNItemCellListHeight = 20.0f;
CGFloat const RNGenericCellHeight = 27.0f;
CGFloat const RNListContainerCellHeight = 38.0f;
CGFloat const RNEmptyHeaderHeight = 10.0f;
CGFloat const RNHeaderHeight = 40.0f;
CGFloat const RNHiddenHeaderHeight = 1.0f;
CGFloat const RNCancelButtonLength = 10.0f;
CGFloat const RNCancelButtonUpperPadding = 4.0f;
CGFloat const RNEditListItemShadowRadius = 3.0f;
NSInteger const RNDragDropTagHighlighted = 8;
NSInteger const RNDragDropTagUnhighlighted = 16;
NSUInteger const RNCountBoxWidth = 100;
NSUInteger const RNCountBoxPadding = 8;
NSUInteger const RNStepperCellHeight = 14;
NSUInteger const RNStepperCellWidth = 40;
NSUInteger const RNDetailCellFavoriteWidth = 12;
NSUInteger const RNDetailCellNotesLength = 16;

#pragma mark -
#pragma mark Utility Functions

NSBezierPath *RNHeartPathWithSize(NSSize heartPathSize) {
    CGFloat smallestDimension = (heartPathSize.height > heartPathSize.width) ? heartPathSize.width : heartPathSize.height;
    NSPoint centerPoint = NSMakePoint((heartPathSize.width / 2), (heartPathSize.height / 2));
        
    NSPoint bottomPoint = centerPoint;
    bottomPoint.y += smallestDimension/2;
    
    NSPoint topPoint = centerPoint;
    topPoint.y -= smallestDimension*5/16;
    
    NSPoint controlPointBottomLeft = bottomPoint;
    controlPointBottomLeft.x -= smallestDimension*0.85;
    controlPointBottomLeft.y -= smallestDimension*0.55;
    
    NSPoint controlPointTopLeft = topPoint;
    controlPointTopLeft.x -= smallestDimension*0.45;
    controlPointTopLeft.y -= smallestDimension*0.5;
    
    NSPoint controlPointBottomRight = bottomPoint;
    controlPointBottomRight.x += smallestDimension*0.85;
    controlPointBottomRight.y -= smallestDimension*0.55;
    
    NSPoint controlPointTopRight = topPoint;
    controlPointTopRight.x += smallestDimension*0.45;
    controlPointTopRight.y -= smallestDimension*0.5;
    
    NSBezierPath *heartPath = [NSBezierPath bezierPath];
    [heartPath moveToPoint:bottomPoint];
    [heartPath curveToPoint:topPoint controlPoint1:controlPointBottomLeft controlPoint2:controlPointTopLeft];
    [heartPath curveToPoint:bottomPoint controlPoint1:controlPointTopRight controlPoint2:controlPointBottomRight];
    return heartPath;
}

NSBezierPath *RNNotesPathWithSize(NSSize notesPathSize) {
    CGFloat smallestDimension = (notesPathSize.height > notesPathSize.width) ? notesPathSize.width : notesPathSize.height;
    NSPoint centerPoint = NSMakePoint(notesPathSize.width / 2, notesPathSize.height / 2);
    CGFloat halfSmallestDimension = floor(smallestDimension / 2);
    CGFloat proportionalHalfSmallestDimension = floor(halfSmallestDimension * 0.84);
//    CGFloat lineWidth = floor(halfSmallestDimension * 0.6);
    NSPoint bottomLeft = centerPoint;
    bottomLeft.x -= proportionalHalfSmallestDimension;
    bottomLeft.y += halfSmallestDimension;
    
    NSPoint topLeft = centerPoint;
    topLeft.x -= proportionalHalfSmallestDimension;
    topLeft.y -= halfSmallestDimension;
    
    NSPoint topRight = centerPoint;
    topRight.x += proportionalHalfSmallestDimension;
    topRight.y -= halfSmallestDimension;
    
    NSPoint bottomRightUpper = centerPoint;
    bottomRightUpper.x += proportionalHalfSmallestDimension;
    bottomRightUpper.y += halfSmallestDimension * 0.36;
    
    NSPoint bottomRightLower = centerPoint;
    bottomRightLower.x += halfSmallestDimension * 0.2;
    bottomRightLower.y += halfSmallestDimension;
    
    NSPoint curlCorner = centerPoint;
    curlCorner.x = bottomRightLower.x;
    curlCorner.y = bottomRightUpper.y;
    
    NSBezierPath *notesPath = [NSBezierPath bezierPath];
    [notesPath setLineWidth:smallestDimension * 0.04];
    [notesPath moveToPoint:bottomLeft];
    [notesPath lineToPoint:topLeft];
    [notesPath lineToPoint:topRight];
    [notesPath lineToPoint:bottomRightUpper];
    [notesPath lineToPoint:bottomRightLower];
    [notesPath closePath];
    [notesPath moveToPoint:bottomRightLower];
    [notesPath lineToPoint:curlCorner];
    [notesPath lineToPoint:bottomRightUpper];
    return notesPath;
}

NSBezierPath* RNCountBoxPathInRect(NSRect countBoxRect) {
    CGFloat minX = NSMinX(countBoxRect);
    CGFloat maxX = NSMaxX(countBoxRect);
    CGFloat minY = NSMinY(countBoxRect);
    CGFloat maxY = NSMaxY(countBoxRect);
    NSBezierPath *countBoxPath = [NSBezierPath bezierPath];
    [countBoxPath moveToPoint:NSMakePoint(maxX, maxY)];
    [countBoxPath lineToPoint:NSMakePoint(minX + RNDetailViewCellCornerRadius, maxY)];
    [countBoxPath appendBezierPathWithArcFromPoint:NSMakePoint(minX, maxY) toPoint:NSMakePoint(minX, maxY - RNDetailViewCellCornerRadius) radius:RNDetailViewCellCornerRadius];
    [countBoxPath lineToPoint:NSMakePoint(minX, minY + RNDetailViewCellCornerRadius)];
    [countBoxPath appendBezierPathWithArcFromPoint:countBoxRect.origin toPoint:NSMakePoint(minX + RNDetailViewCellCornerRadius, minY) radius:RNDetailViewCellCornerRadius];
    [countBoxPath lineToPoint:NSMakePoint(maxX, minY)];
    [countBoxPath closePath];
    return countBoxPath;
}
